package cn.hongxin.sap.conn.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
    public static void main(String[] args) {
        /*String type = "sapconfig1";
        switch (type){
            case "sapconfig":
                System.out.println("sapconfig");
                break;
            default:
                System.out.println("default");
                break;
        }*/
        String s = "<@A.budget@>,<@A.money@>";
        String quStr=s.substring(s.indexOf("<@")+2,s.indexOf("@>"));
        //System.out.println(quStr);
        //getFiles("F:\\\\companyres\\\\gitRep\\\\BSMVC\\\\MyMvcProJectManager\\\\Scripts\\\\Kindeditor\\\\attached\\\\file");
        getFiles("F:\\software\\quick");
    }

    public static void ff() {

        //String msg = "PerformanceManager[第1个中括号]Product[第2个中括号]<[第3个中括号]79~";
        String msg = "<@A.budget@>,<@A.money@>";
        List<String> list = extractMessageByRegular(msg);
        for (int i = 0; i < list.size(); i++) {
            String temp = list.get(i);
            System.out.println(i+"\t"+temp.substring(temp.indexOf(".")+1));
            //System.out.println(list.get(i).substring(list.get(i).indexOf("\\.")));
        }
    }

    /**
     * 使用正则表达式提取中括号中的内容
     * @param msg
     * @return
     */
    public static List<String> extractMessageByRegular(String msg){
        List<String> list=new ArrayList<>();
        Pattern p = Pattern.compile("<@.+?@>");
        Matcher m = p.matcher(msg);
        while(m.find()){
            list.add(m.group().substring(2, m.group().length()-2));
        }
        return list;
    }


    public static Map<String,ArrayList<String>> getFiles(String path) {
        Map<String,ArrayList<String>> map = new HashMap<>();
        ArrayList<String> files = new ArrayList<String>();
        ArrayList<String> dirs = new ArrayList<String>();
        File file = new File(path);
        File[] tempList = file.listFiles();

        for (int i = 0; i < tempList.length; i++) {
            if (tempList[i].isFile()) {
                System.out.println("文     件：" + tempList[i]);
                files.add(tempList[i].toString());
            }
            if (tempList[i].isDirectory()) {
                System.out.println("文件夹：" + tempList[i]);
                dirs.add(tempList[i].toString());
            }
        }
        map.put("dirs",dirs);
        map.put("files",files);
        return map;
    }
}
